﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class glDRIVE
{
    /*
    函数 gl.srrt
    代数方程牛顿下山法
    参数 Ar: a[n+1]存放n次多项式的n+1个复系数 实部。
    参数 Ai: a[n+1]存放n次多项式的n+1个复系数 虚部。
    参数 n: n多项式方程的次数。
    参数 Xr: xx[n]返回n个复根 实部。
    参数 Xi: xx[n]返回n个复根 虚部。
    返回值 函数返回标志值。若<0则表示多项式为零次多项式；否则正常返回。
    */

    public static string drive_srrt()
    {
        int i;
        complex[] z = new complex[6];
        complex[] b = new complex[6];
        complex[] a = new complex[6] {
            new complex(0.1,-100),
            new complex(21.33,0.0),
            new complex(4.9,-19.0),
            new complex(0.0,-0.01),
            new complex(3.0,3.0),
            new complex(1.0,0.0)
        };
        for (i = 0; i <= 5; i++) b[i] = a[i];
        //com_poly p;
        //p = com_poly(5, a);

        double[] ar = new double[6];
        for (i = 0; i <= 5; i++) ar[i] = a[i].R;
        double[] ai = new double[6];
        for (i = 0; i <= 5; i++) ai[i] = a[i].I;
        double[] zr = new double[6];
        double[] zi = new double[6];

        i = gl.srrt(ar, ai, 5, zr, zi);

        for (i = 0; i <= 5; i++) z[i] = new complex(zr[i], zi[i]);

        string rs = "";

        rs += gl.html_table("Ar", ar);
        rs += gl.html_table("Ai", ai);
        rs += gl.html_table("Zr", zr);
        rs += gl.html_table("Zi", zi);

        /*
        if (i > 0)
        {
            for (i = 0; i <= 4; i++)
            {
                ; // cout <<"z(" <<i <<") = "; z[i].prt(); ; // cout <<endl;
            }
            ; // cout <<"检验:" <<endl;
            for (i = 0; i <= 4; i++)
            {
                ; // cout <<"f(" <<i <<") = ";
                p.poly_value(z[i]).prt(); ; // cout <<endl;
            }
        }
        return "error: 0";
        */
        return rs;
    }
}